import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
const state = {
  loadingList: [],
  eq:1,
};
const mutations = {
  PUSH_LOADING (state, playload) {
    state.loadingList.push({text: playload || '玩命加载中...'})
  },
  SHIFT_LOADING (state) {
    state.loadingList.shift()
  },
  setEq(state,{data}){
    state.eq = data;
  }
}
const getters = {
  isLoading (state) {
    return state.loadingList.length > 0
  },
  loadingText (state) {
    return state.loadingList.length > 0 ? state.loadingList[0].text : null
  }
}
const actions = {
  //请求数据时状态loading
  openLoading (contaxt, playload) {
    contaxt.commit('PUSH_LOADING', playload)
  },
  closeLoading (contaxt) {
    contaxt.commit('SHIFT_LOADING')
  }
}


export default new Vuex.Store({
	state,
	mutations,
  getters,
  actions
})
